
export const getData = (item) => {
  return {
    ...item.currentTarget.dataset,
  }
}

export const getItem = (item) => {
  return getData(item).item;
}

export const trim = (str) => {
  if (str) {
    return `${str||''}`.trim()
  }
  return ''
}

export const isNullObject = (obj) => {
  if (obj && Object.keys(obj).length > 0) {
    return false;
  }
  return true;
}

export const objToUrl = (obj) => {
  if (isNullObject(obj)) {
    return ''
  }
  // const queryString = new URLSearchParams(obj).toString(); // 不支持
  const queryString = Object.entries(obj)
  .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
  .join('&');
  return queryString
}

export const urlMapping = (jsFile) => {
  let router = __wxConfig.pages;
  let arr = jsFile.split('.')
  let path = undefined;
  for (let i = 0; i < router.length; i++) {
    if (router[i].endsWith(`/${arr[0]}`)) {
      path = router[i]
      break;
    }
  }
  return path;
}